package com.itheima.d7_TCP_Multiple;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

/**
 *  public ThreadPoolExecutor(int corePoolSize,
 *                               int maximumPoolSize,
 *                               long keepAliveTime,
 *                               TimeUnit unit,
 *                               BlockingQueue<Runnable> workQueue,
 *                               ThreadFactory threadFactory,
 *                               RejectedExecutionHandler handler)
 */
public class Server1 {
    public static void main(String[] args) throws IOException {
        ExecutorService pool = new ThreadPoolExecutor(2, 5, 8
                , TimeUnit.SECONDS, new ArrayBlockingQueue<>(2)
                , Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
        //思路: pool只能执行任务，所以我需要将创建管道，接受数据这个过程包装成任务

        ServerSocket serverSocket = new ServerSocket(6666);

        while (true) {
            Socket socket = serverSocket.accept();
            Runnable myRunnable = new MyRunnable(socket);
            pool.execute(myRunnable);
        }
    }

}
